﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace BusinessLogic.Command
{
    public class MaintainTXCommand : BaseCommand<APP_PERSONAL>
    {
        private APP_PERSONAL P;

        public MaintainTXCommand(APP_PERSONAL APP_PERSONALInfo)
        {
            P = APP_PERSONALInfo;
        }

        public override void Command()
        {
            CubeOfDB2Entities ctx = new CubeOfDB2Entities();
            
            if (P.ID == 0)
            {
                ctx.APP_PERSONAL.AddObject(P);
            }
            else
            {
                var pers = ctx.APP_PERSONAL.Where(o => o.ID == P.ID).FirstOrDefault();
                if (pers != null)
                {
                    pers.FNAME_EN = P.FNAME_EN;
                    pers.LNAME_EN = P.LNAME_EN;
                    pers.EMAIL = pers.EMAIL;
                    pers.POSITION = P.POSITION;
                    pers.NOTE = P.NOTE;
                }
            }

            ctx.SaveChanges();
        }
    }
}
